home *** CD-ROM | disk | FTP | other *** search
- /*
- * pn.c - postnews command for bootstrap news
- * copyright 1989 Ronald Florence (ron@mlfarm 7/9/89)
- *
- * Originally written as a shell script in the original bsnews
- * package. Re-written as a C program for use with MT C-Shell
- * by David Beckemeyer (david@bdt 8/23/89)
- *
- */
-
- #include <stdio.h>
- #include <osbind.h>
- #include <types.h>
- #include <time.h>
-
- extern char *ctime();
- extern char **environ;
-
- extern char *feedhost();
-
- #define SEQFILE "\\usr\\lib\\news\\seq"
- #define ORGFILE "\\usr\\lib\\news\\org"
- #define TMPART "\\tmp\\newsart"
-
- #define EDITOR "\\usr\\bin\\me.prg"
- #define UUXPRG "\\usr\\bin\\uux.prg"
-
- char *seqfile = SEQFILE;
- char *tmpart = TMPART;
- char *ctlfile = "\\usr\\spool\\uucp\\uucp.ctl";
-
- char line[512];
-
- char *lname()
- {
- FILE *fp;
- char *s;
-
- if ((fp = fopen(ctlfile, "r")) == 0) {
- fprintf(stderr, "cannot open %s\n", ctlfile);
- exit(1);
- }
- while (fgets(line, 512, fp)) {
- if (strncmp(line, "nodename", 8) == 0) {
- for (s = line+9; *s > ' '; s++)
- ;
- *s = 0;
- return(line+9);
- }
- }
- fclose(fp);
- return(0);
- }
-
-
- char *getorg()
- {
- FILE *fp;
- static char orgbuf[80];
-
- if ((fp = fopen(ORGFILE, "r")) == 0) {
- printf("cannot open %s\n", ORGFILE);
- exit(1);
- }
- if (!fgets(orgbuf, 80, fp)) {
- printf("cannot read %s\n", ORGFILE);
- exit(1);
- }
- fclose(fp);
- orgbuf[strlen(orgbuf)-1] = 0;
- return(orgbuf);
- }
-
- seq()
- {
- FILE *fp;
- char buf[32];
- int x;
-
- if ((fp = fopen(seqfile, "r")) == 0) {
- fprintf(stderr, "cannot open %s\n", seqfile);
- exit(1);
- }
- if (fgets(buf, 32, fp) == 0)
- x = 0;
- else
- x = atoi(buf);
- fclose(buf);
- return(x);
- }
-
- incr()
- {
- int x;
- FILE *fp;
-
- x = seq();
-
- if ((fp = fopen(seqfile, "w")) == 0) {
- fprintf(stderr, "cannot open %s\n", seqfile);
- exit(1);
- }
- fprintf(fp, "%d\n", x+1);
- fclose(fp);
- }
-
- static char *edtargv[] = {
- EDITOR,
- TMPART,
- 0
- };
-
- editit()
- {
- execve(EDITOR, edtargv, environ);
- }
-
- static char uuxcmd[64];
-
- static char *uuxargv[] = {
- "uux", "-", uuxcmd, 0
- };
-
- main()
- {
- FILE *tmpfp;
- char groups[80];
- char subject[80];
- char yn[10];
- char *sys, *user, *getenv();
- time_t t;
-
- if ((user = getenv("USER")) == 0) {
- fprintf(stderr, "USER undefined\n");
- exit(1);
- }
- if ((sys = lname()) == 0) {
- fprintf(stderr, "nodename undefined\n");
- exit(1);
- }
-
- printf("Enter Newsgroups: ");
- fflush(stdout);
- gets(groups);
- printf("Enter Subject: ");
- fflush(stdout);
- gets(subject);
-
- time(&t);
- tmpfp = fopen(tmpart, "w");
- if (tmpfp == 0) {
- fprintf(stderr, "cannot open %s\n", tmpart);
- exit(1);
- }
- fprintf(tmpfp, "Path: %s!%s\n", sys, user);
- fprintf(tmpfp, "From: %s@%s.UUCP\n", user, sys);
- fprintf(tmpfp, "Newsgroups: %s\n", groups);
- fprintf(tmpfp, "Subject: %s\n", subject);
- fprintf(tmpfp, "Message-ID: <%d@%s.UUCP>\n", seq(), sys);
- fprintf(tmpfp, "Date: %s", ctime(&t));
- fprintf(tmpfp, "Followup-To: \n");
- fprintf(tmpfp, "Distribution:\n");
- fprintf(tmpfp, "Keywords: \n");
- fprintf(tmpfp, "Organization: %s\n", getorg());
- fprintf(tmpfp, "Lines: \n\n\n");
- fclose(tmpfp);
-
- printf("Invoking editor...\n");
- fflush(stdout);
-
- editit();
-
- printf("Post to all of usenet? ");
- fflush(stdout);
- gets(yn);
- if (yn[0] == 'y') {
- printf("posting article...\n");
- sprintf(uuxargv[2], "%s!rnews", feedhost());
- invoke(UUXPRG, uuxargv, tmpart, "");
- incr();
- }
- else
- printf("cancelled\n");
- exit(0);
- }
-
-
- extern char *environ;
- extern int errno;
- extern char *_iovector;
-
- /* Invoke the local program. Return its status (0 == ok) or -1 */
- invoke(file, argv, input, output)
- char *file, *argv[], *input, *output;
- {
- char tmp[128];
- int fd0, fd1, std0, std1, err;
- char env[128], *p;
-
- /* save the MWC io setup */
- strcpy(env, _iovector);
- if (strlen(input)) {
- strcpy(tmp, input);
- std0 = Fdup(0);
- fd0 = Fopen(tmp, 0);
- if (fd0 > 0) {
- _iovector[0] = 'F';
- Fforce(0, fd0);
- }
- else
- printf("cannot open %s as stdin\n", tmp);
- }
- if (strlen(output)) {
- strcpy(tmp, output);
- std1 = Fdup(1);
- fd1 = Fopen(tmp, 0);
- if (fd1 > 0) {
- _iovector[1] = 'F';
- Fforce(1, fd1);
- }
- else
- printf("cannot open %s as stdout\n", tmp);
- }
- err = execve(file, argv, environ);
- if (strlen(input)) {
- Fclose(fd0);
- Fforce(0, std0);
- }
- if (strlen(output)) {
- Fclose(fd1);
- Fforce(1, std1);
- }
- /* restore MWC io for stdio calls */
- strcpy(_iovector, env);
- if (err)
- printf("exec failed %d (errno=%d)\n", err, errno);
- return(err);
- }
-